﻿Imports System.IO
Public Class helpScreen

    Public inputFile As String
    Dim rtfWidth As Integer, rtfHeight As Integer
    Dim textWidth As Integer, textHeight As Integer
    Dim formHeight As Integer, formWidth As Integer

    Private Sub helpScreen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim fileLoc As String

        rtfWidth = 731
        rtfHeight = 360
        textWidth = 731
        textHeight = 360
        formWidth = 764
        formHeight = 416

        Call helpScreen_Resize(sender, e)

        fileLoc = inputFile

        textHelp.Visible = False
        help.Visible = True ' assume the file is RTF

        If Not System.IO.File.Exists(fileLoc) Then ' the filename exists where we are looking - use it
            fileLoc = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location()) & "\" & inputFile
            If Not System.IO.File.Exists(fileLoc) Then
                textHelp.Visible = True
                help.Visible = False
                textHelp.Text = "Help file '" & inputFile & "' not found in either:" & vbCrLf & _
                                "    1. the current directory " & vbCrLf & _
                                "    2. " & System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location()) & vbCrLf & _
                                "    3. " & fileLoc
                Exit Sub
            End If
        End If

        If UCase(Mid(inputFile, InStrRev(inputFile, ".") + 1)) = "RTF" Then
            help.LoadFile(fileLoc)
        Else
            textHelp.Visible = True
            help.Visible = False

            Dim txtReader As New StreamReader(fileLoc)
            Do While txtReader.Peek <> -1
                textHelp.Text = textHelp.Text & Trim(txtReader.ReadLine()) & vbCrLf
            Loop

            txtReader.Close()

        End If


        Select Case UCase(inputFile)
            Case Is = "BATCHHANDBRAKE.TXT"
                Me.Text = "batchHandBrake Help"
            Case Is = "BATCHHANDBRAKE.RTF"
                Me.Text = "batchHandBrake Help"
            Case Is = "BATCHHANDBRAKE.TXT"
                Me.Text = "batchHandBrake Version History"
            Case Is = "BATCHHANDBRAKE.RTF"
                Me.Text = "batchHandBrake Version History"
            Case Else
                Me.Text = "batchHandBrake Help"
        End Select
        Me.Text = Me.Text & "   - " & inputFile

    End Sub

    Private Sub helpScreen_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState <> FormWindowState.Minimized Then

            If Me.Width < formWidth Then Me.Width = formWidth
            If Me.Height < formHeight Then Me.Height = formHeight

            help.Width = Me.Width - (formWidth - rtfWidth)
            help.Height = Me.Height - (formHeight - rtfHeight)
            textHelp.Width = Me.Width - (formWidth - textWidth)
            textHelp.Height = Me.Height - (formHeight - textHeight)
        End If
    End Sub

    Private Sub textHelp_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textHelp.TextChanged

    End Sub
End Class